#with语句:能自动管理上下文资源，不管什么原因跳出with，都能确保文件正常的关闭，以此达到释放资源目的
with open('a.txt', 'r', encoding='utf-8') as file:
    print(file.read())
print()

print(2)
class MyContentMgr(object):
    def __enter__(self):
        print('enter方法被调用!')
        return self
    def __exit__(self, exc_type, exc_val, exc_tb):
        print('exit方法被调用!')
    def show(self):
        print('show方法被调用!')

with MyContentMgr() as file:
    file.show()